| Conditions | 1 |
| Total Lines | 16 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 4 |
| CRAP Score | 1.2577 |
| Changes | 0 | ||
| 1 | import { useDispatch } from 'react-redux'; |
||
| 5 | |||
| 6 | export default function Logout(props: ButtonProps) { |
||
| 7 | |||
| 8 | 2 | const dispatch = useDispatch(); |
|
| 9 | 2 | const navigate = useNavigate(); |
|
| 10 | |||
| 11 | 2 | const logOutUser = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { |
|
| 12 | e.preventDefault(); |
||
| 13 | dispatch(setLoggedInOut(false)); |
||
| 14 | dispatch(setCurrentUser(null)); |
||
| 15 | dispatch(setToken('')); |
||
| 16 | dispatch(setRole('guest')); |
||
| 17 | navigate('/'); |
||
| 18 | } |
||
| 19 | 2 | return ( |
|
| 20 | <Button {...props} data-testid="logoutbutton" color="failure" onClick={(e) => logOutUser(e)}>Logga ut</Button> |
||
| 21 | ) |
||
| 23 |